package dao

import (
	"fmt"
	"waimai/model"
	"waimai/tool"
)

type MemberDao struct {
	*tool.Orm
}
func(md *MemberDao) ValidateSmsCode(phone string,code string)(*model.SmsCode){
	var sms model.SmsCode
	if _,err:=md.Where("phone = ? and code = ?",phone,code).Get(&sms);err!=nil{
		fmt.Println(err.Error())
	}
	return &sms
}

func (md *MemberDao) QueryByPhone(phone string)*model.Member{
	var memeber model.Member
	if _,err:=md.Where("mobile=?",phone).Get(&memeber);err!=nil{
		fmt.Println(err.Error())
	}
	return &memeber
}

func (md *MemberDao)Query(name string,password string)*model.Member{
	var memeber model.Member
	_,err:=md.Where("username=? and password=?",name,password).Get(&memeber)
	if err!=nil{
		fmt.Println(err.Error())
		return nil
	}
	return &memeber
}

func (md *MemberDao) InsertMember(member model.Member)int64{
	result,err:=md.InsertOne(&member)
	if err!=nil{
		fmt.Println(err.Error())
		return 0
	}
	return result
}

func (md *MemberDao)InsertCode(sms *model.SmsCode)int64{
	result,err:=md.InsertOne(sms)
	if err !=nil{
		fmt.Println(err.Error())
		return 0
	}

	return result
}